package com.wc.alorithm_blue_bridge._DFS.跳石头;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/5/1 14:00
 * @description
 * https://www.lanqiao.cn/problems/20151/learning/?problem_list_id=32&page=1
 */
public class Main {
    /**
     * 思路：
     * bfs, 将所有可能的值都加入到队列当中, 也就是能够达到的位置
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 40010;
    static int[] a = new int[N], ans = new int[N];
    static boolean[] st = new boolean[N], state = new boolean[N];
    static int[] q = new int[N << 1];
    static int n;

    public static void main(String[] args) {
        n = sc.nextInt();
        for (int i = 1; i <= n; i++) a[i] = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            if (!state[i]) bfs(i);
        }

        int res = 0;
        for (int i = 1; i <= n; i++) res = Math.max(res, ans[i]);
        out.println(res);
        out.flush();
    }

    static void bfs(int u) {
        int hh = 0, tt = -1;
        HashSet<Integer> set = new HashSet<>();
        Arrays.fill(st, 1, n + 1, false);
        q[++tt] = u;
        while (hh <= tt) {
            int t = q[hh++];
            if (st[t]) continue;
            st[t] = true;
            state[t] = true;
            set.add(a[t]);
            if (2 * t <= n) q[++tt] = 2 * t;
            if (t + a[t] <= n) q[++tt] = t + a[t];
        }
        ans[u] = set.size();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

